<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>新增pid</title>
        <link rel="stylesheet" href="__STATIC__/layui/css/layui.css" media="all">
         <script src="__STATIC__/index/js/jquery-3.2.1.js"></script>
        <script src="__STATIC__/layui/layui.js"></script>
    </head>
    <body>
        <form class="layui-form"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
        	<input type="hidden" name="id" value="{$pid_uid}" >
            <div class="layui-form-item">
                <label class="layui-form-label">请选择PID</label>
                <div class="layui-input-block">
                	
                    <select name="pid">
                    	{foreach $pid_arr as $v}
                    	 {if $v.status==1}
                    	<option value="{$v.pid}" selected = "selected">{$v.pid}</option>
                    	{else}
                    	<option value="{$v.pid}">{$v.pid}</option>
                    	{/if}
                    	{/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="*" id="button_from">更新</button>
                </div>
            </div>
            <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
        </form>
       
        <script>
            layui.use('form', function(){
                var form = layui.form;
                form.on('submit(*)', function(data){
                	//console.log(data);
                	var field = data.field;
                	var id = field.id;
                	var pid = field.pid;
                	$('#button_from').attr('disabled','disabled');	 
                	$.ajax({
                		type:"post",
                		url:"{:url('market/update_pid')}",
                		data:{id:id,pid:pid},
                		success:function(res){
                		   if(res.code==0){
	                		   	  layui.use('layer', function(){
					              var layer = layui.layer;
					              layer.alert(res.msg, {icon: 2},function(){
					              	$('#button_from').removeAttr('disabled');
					              	location.reload(); 
					              });
					              });              
			 		        return false;
                		   }else if(res.code==1){
                		   	       layui.use('layer', function(){
					               var layer = layui.layer;
					               layer.alert(res.msg, {icon: 1},function(){
                                   $('#button_from').removeAttr('disabled');
									window.parent.getChild();
					              });
					              });  
					        return false;
                		   }

                		}
                	});
                	
                    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                });
            });   
        </script>
    </body>
</html>
